﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TimeCapsule;

public partial class Auth : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (Request.QueryString.Get("type") == null || Request.QueryString.Get("key") == null)
		{
			ErrorMessage.Set(ErrorCode.ParamError);
			Util.CheckError();
			return;
		}

		switch (int.Parse(Request.QueryString.Get("type")))
		{
			case 0:
				RegisterAuth(Request.QueryString.Get("key"));
				break;
			default:
				break;
		}

	}

	private void RegisterAuth(string key)
	{
		dbAccess da = new dbAccess();
		DataSet ds = da.GetTempUser(key);
		
		if( ds.Tables[0].Rows.Count != 0 )
			da.ActivateUser(ds.Tables[0].Rows[0]["Email"].ToString());
		
		Response.Redirect("~/Login.aspx");
	}
}
